// pages/discover/tradeinfo/tradeinfo.js
const util = require('../../../utils/util.js')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    information: {},
    createTime:'',
    deadline:'',
    complaintype: [
      '垃圾信息', '不良信息', '分类不规范', '其他'
    ],
    showComplainModal: false,
    showModal: false,
    showTradeModal: false,
    index: 0,
    date: '2018-04-01',
    time: '12:01',

    price: '',
    description: '',
    reason: '',
    complaintType:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      information: app.globalData.info_detail
    })
    this.setData({
      createTime: util.formatTime(this.data.information.information.createTime),
      deadline: util.formatTime(this.data.information.information.deadline)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
  },
  bindTimeChange: function (e) {
    this.setData({
      time: e.detail.value
    })
  },
  descripChange: function (e) {
    this.setData({
      description: e.detail.value
    })
  },
  priceChange: function (e) {
    this.setData({
      price: e.detail.value
    })
  },
  reasonChange: function (e) {
    this.setData({
      reason: e.detail.value
    })
  },
  typePickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    if (e.detail.value == 0) {
      this.setData({
        complaintType: '垃圾信息'
      })
    }
    else if (e.detail.value == 1) {
      this.setData({
        complaintType: '不良信息'
      })
    }
    else if (e.detail.value == 2) {
      this.setData({
        complaintType: '分类不规范'
      })
    } else {
      this.setData({
        complaintType: '其他'
      })
    }
  },

  hideModal: function () {
    this.setData({
      showComplainModal: false,
      showModal: false,
      showTradeModal: false
    });
  },
  onComplainCancel: function () {
    this.hideModal();
  },
  onComplainConfirm: function () {
    this.hideModal();
  },
  complainBtn: function () {
    this.setData({
      showComplainModal: true,
      showModal: true,
    })
  },
  onTradeCancel: function () {
    this.hideModal();

  },


  /**    
   * 确认交易
  */
  onTradeConfirm: function () {
    var that = this;
    var guaranteTime = that.data.date + ' ' + that.data.time;
    util.addIndent(that.data.price, that.data.description, that.data.information.information.informationId, guaranteTime, that.data.information.user.userId)
    that.hideModal();
    wx.navigateBack({
    })
  },


  /**    
   * 确认投诉
  */
  onComplainConfirm: function () {
    var that = this;
    util.addComplaint(that.data.complaintType, that.data.reason, that.data.information.information.informationId)
    that.hideModal();
    wx.navigateBack({
    })
  },

  tradeBtn: function () {
    this.setData({
      showTradeModal: true,
      showModal: true,
    })
  },

  collectBtn: function(){
    util.addCollect(app.globalData.userId,this.data.information.information.informationId),
    wx.navigateBack({
    })
  },

  cancelCollectBtn: function () {
    util.removeCollect(app.globalData.userId, this.data.information.information.informationId),
    wx.navigateBack({
    })
  }
})